package config

import (
	"fmt"

	"github.com/spf13/viper"
)

func GenarateMysqlDsn(v *viper.Viper) string {
	user := v.GetString("mysql.user")
	password := v.GetString("mysql.password")
	host := v.GetString("mysql.host")
	port := v.GetInt("mysql.port")
	database := v.GetString("mysql.database")
	charset := v.GetString("mysql.charset")
	timeout := v.GetInt("mysql.timeout")

	return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=True&loc=Local&timeout=%ds",
		user,
		password,
		host,
		port,
		database,
		charset,
		timeout)

}
